package edu.ycxy.poetry.config;

import edu.ycxy.poetry.interceptor.PathInterceptor;
import lombok.experimental.Accessors;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author @xin
 * @createDate 2022/4/29
 * @Description 自定义路径拦截器
 */
@Configuration
@Accessors(chain = true)
public class PathInterceptorConfigurer implements WebMvcConfigurer {

    // 拦截器配置
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        // 创建拦截器对象
        HandlerInterceptor interceptor = new PathInterceptor();


        // 白名单
        List<String> patterns = new ArrayList<>();
        patterns.add("/bootstrap-4.6.1-dist/**");
        patterns.add("/common/**");
        patterns.add("/image/**");
        patterns.add("/admin/assets/**");
        patterns.add("/*");
        patterns.add("/poems/**");
        patterns.add("/booklei/**");
        patterns.add("/dynasty/**");
        patterns.add("/idiom/**");
        patterns.add("/djInfo/**");
        patterns.add("/djList/**");
        patterns.add("/type/**");
        patterns.add("/trans/**");
        patterns.add("/user/**");
        patterns.add("/writer/**");
        patterns.add("/know/**");
        patterns.add("/ju/**");



        // 通过注册工具添加拦截器
        registry.addInterceptor(interceptor).addPathPatterns("/**").excludePathPatterns(patterns);
    }
}
